/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
;
var spc = jQuery.extend({}, spc);/* 全局对象 */

(function($) {
    $.parser.onComplete = function() {/* 页面所有easyui组件渲染成功后，隐藏等待信息 */
        window.setTimeout(function() {
            $('#index_div_pageLoading').fadeOut(1000);
        }, 1);
    };
    /*
     * jeasyui 相关的配置
     */
    $.fn.panel.defaults.loadingMessage = '数据加载中，请稍候......';

    $.fn.datagrid.defaults.onLoadError = function(XMLHttpRequest) {/* 扩展dataGrid出现错误的提示 */
        $.messager.alert('提示', XMLHttpRequest.responseText, 'error');
    };
    $.ajaxSetup({
        error : function(XMLHttpRequest, textStatus, errorThrown) {/* 扩展AJAX出出现错误的提示 */
            $.messager.alert('提示', XMLHttpRequest.responseText, 'error');
        }
    });
    
    //SPC本身的扩展
    /**
     * 增加命名空间功能
     * 使用方法：sy.ns('jQuery.bbb.ccc','jQuery.eee.fff');
     */
    spc.ns = function() {
        var o = {}, d;
        for ( var i = 0; i < arguments.length; i++) {
            d = arguments[i].split(".");
            o = window[d[0]] = window[d[0]] || {};
            for ( var k = 0; k < d.slice(1).length; k++) {
                o = o[d[k + 1]] = o[d[k + 1]] || {};
            }
        }
        return o;
    };
    /**
     * 获得项目根路径
     * 
     * 使用方法：sy.bp();
     */
    spc.bp = function() {
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        var localhostPaht = curWwwPath.substring(0, pos);
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
        return (localhostPaht + projectName);
    };   
    
    spc.showLoadingDiv = function() {
        var loadingDiv = $('#_AJAXLOADINGDIV_');
        if (loadingDiv.length < 1) {
            $("body").append('<div id="_AJAXLOADINGDIV_" style="z-index: 9999999; position: absolute; top: 0px; right: 0px; background-color:#FFFEE6; color:#8F5700; padding:5px;"><div>数据处理中,请稍候......</div></div>');
        } else {
            loadingDiv.show();
        }
    };
    /**
     * AJAX结束时隐藏提示信息
     */
    spc.hideLoadingDiv = function() {
        $('#_AJAXLOADINGDIV_').fadeOut(500);
    };
    /**
	 * 为jQuery的ajax提供等待提示
	 */
    $(document).ajaxStart(spc.showLoadingDiv).ajaxStop(spc.hideLoadingDiv);
    /*
     * jeasyui 的扩展
     * 
     */
    $.extend($.fn.validatebox.defaults.rules, {  
        safestr: {  
            validator: function(value, param){
                var reCat = /([\uff00-\uffff]+|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]+)/i;
                return !reCat.test(value);  
            },  
            message: '不能包含 -_~!@#$%^&*.或全角等字符。 '  
        }
        
    });
})(jQuery);

